<template>
  <div>
    <el-table :data="tableData" style="width: 100%; height: 100%">
      <el-table-column
        v-for="(item, index) in tableHeader"
        :key="index"
        :label="item.label"
        :prop="item.prop"
        :width="item.width ? item.width : 'auto'"
        align="center"
      >
        <!-- 可以自定义标头写法 -->
        <!-- <template slot-scope="scope">
          <span>{{ scope.row[item.prop] }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="操作" align="center" v-if="caozuo">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-edit"
            size="mini"
            style="margin-right: 10px"
            @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-popconfirm
            confirm-button-text="好的"
            cancel-button-text="不用了"
            icon="el-icon-info"
            icon-color="red"
            title="这是一段内容确定删除吗？"
            @confirm="handleDelete(scope.$index, scope.row)"
          >
            <el-button
              icon="el-icon-delete"
              size="mini"
              type="danger"
              slot="reference"
              >删除</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pag"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="config.currentPage"
      :page-sizes="[5, 10, 15]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="config.total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'ManageTable',
  props: {
    tableData: Array,
    tableHeader: Array,
    config: {
      type: Object,
      default() {
        return {
          total: 1,
          currentPage: 1,
        };
      },
    },
    caozuo: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },

  mounted() {},

  methods: {
    handleEdit(i, r) {
      this.$emit('edit', r);
    },
    handleDelete(i, r) {
      this.$emit('del', r);
    },
    handleCurrentChange(e) {
      this.$emit('currpage', e);
    },
    handleSizeChange(e) {
      this.$emit('currsize', e);
    },
  },
};
</script>

<style lang="less" scoped>
.pag {
  float: right;
  margin: 10px 10px 0 0;
}
</style>
